package com.zhihu_lvliangi_android.option.home.adapter;

import com.zhihu_lvliangi_android.R;
import com.zhihu_lvliangi_android.util.ViewHolder;

import android.R.integer;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class zhengwuAdapter extends BaseAdapter {
	private Context mContext;
	private TypedArray mIds;
	private String[] mTitles;

	public zhengwuAdapter(Context context,TypedArray ids,String[] titles) {
		this.mContext = context;
		this.mIds = ids;
		this.mTitles = titles;

	}

	@Override
	public int getCount() {
		//return mIds.length();
		return mTitles.length;
	}

	@Override
	public Object getItem(int position) {
		//return mIds.getResourceId(position, 0);
		return mTitles[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView  = LayoutInflater.from(mContext).inflate(R.layout.general_gridview_item,null);
		}
		ImageView imageView = ViewHolder.get(convertView, R.id.general_grid_view_item_img);
		TextView textView = ViewHolder.get(convertView, R.id.general_grid_view_item_txt);
//		imageView.setImageResource(mIds.getResourceId(position, 0));
		if (position>mIds.length()) {
			imageView.setImageResource(mIds.getResourceId(mIds.length(), 0));
		}else {
			imageView.setImageResource(mIds.getResourceId(position, 0));
		}
		textView.setText(mTitles[position]);
		if ((position%2 == 0) && mTitles.length > 1 ) {
			ViewHolder.get(convertView, R.id.linerigh).setVisibility(View.VISIBLE);
			
		}
		if ( (mTitles.length-position)/2>0) {
			ViewHolder.get(convertView, R.id.linedown).setVisibility(View.VISIBLE);
		}
		if (mTitles.length >2 && mTitles.length %2 == 0  && mTitles.length-2 == position) {
			ViewHolder.get(convertView, R.id.linedown).setVisibility(View.GONE);
		}

//		if ((mTitles.length-position)/2>0) {
//			ViewHolder.get(convertView, R.id.linedown).setVisibility(View.VISIBLE);
//		}

		return convertView;
	}

}
